package com.xq.controller;

import com.xq.response.Result02;
import com.xq.utils.OssUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @title: OssController
 * @Author Tan
 * @Date: 2020/8/1 15:05
 * @Version 1.0
 */
@Api("上传文件到阿里oss")
@RequestMapping("/aliOss")
@RestController
@CrossOrigin
public class OssController {
    @Autowired
    private OssUtil ossUtil;

    @ApiOperation(value = "图片上传",notes = "图片上传到oss")
    @PostMapping("/uploadFileImage")
    public String uploadFileImage(MultipartFile file) throws IOException {
        System.out.println(file.toString()+"ddd");
        String fileUrl = ossUtil.uploadFile(file);
        Map<String,Object> map=new HashMap<>();
        map.put("fileUrl",fileUrl);
        return fileUrl;
    }

    @ApiOperation(value = "下载图片",notes = "下载到本地")
    @PostMapping("/downloadFileImage")
    public String downloadFileImage(){
        ossUtil.downloadLocalFile();
        return "success";
    }
}